import Vue from 'vue'
import VueRouter from 'vue-router'
const CategoryList = () => import('../views/Category/CategoryList.vue')
const ItemEdit = () => import('../views/Item/ItemEdit.vue')
const ItemList = () => import('../views/Item/ItemList.vue')
const HeroEdit = () => import('../views/Hero/HeroEdit.vue')
const HeroList = () => import('../views/Hero/HeroList.vue')
const InscList = () => import('../views/Insc/InscList.vue')
const InscEdit = () => import('../views/Insc/InscEdit.vue')
const ResetPwd = () => import('../views/Login/ResetPwd.vue')
const SkillEdit = () => import('../views/Skill/SkillEdit.vue')
const SkillList = () => import('../views/Skill/SkillList.vue')
const UserList = () => import('../views/User/UserList.vue')
const InviList = () => import('../views/Invi/InviList.vue')
const Report = () => import('../views/Invi/Report.vue')
const CategoryEdit = () => import('../views/Category/CategoryEdit.vue')
const Main = () => import('../views/Main.vue')
const Login = () => import('../views/Login/Login.vue')
const Chart = () => import('../views/Chart/Chart.vue')
const InforList = () => import('../views/Infor/InforList.vue')
const InforEdit = () => import('../views/Infor/InforEdit')
Vue.use(VueRouter)

const routes = [{
  path: '/',
  redirect: '/login'
}, {
  path: '/login',
  component: Login
}, {
  path: '/main',
  component: Main,
  children: [{
    path: '/main',
    redirect: '/categories/list'
  }, {
    path: '/reset',
    component: ResetPwd
  }, {
    path: '/categories/create',
    component: CategoryEdit
  }, {
    path: '/categories/list',
    component: CategoryList
  }, {
    path: '/categories/edit/:id',
    component: CategoryEdit,
    props: true
  }, {
    path: '/item/create',
    component: ItemEdit
  }, {
    path: '/item/list',
    component: ItemList
  }, {
    path: '/item/edit/:id',
    component: ItemEdit,
    props: true
  }, {
    path: '/hero/create',
    component: HeroEdit
  }, {
    path: '/hero/list',
    component: HeroList
  }, {
    path: '/hero/edit/:id',
    component: HeroEdit,
    props: true
  }, {
    path: '/inscription/list',
    component: InscList
  }, {
    path: '/inscription/edit/:id',
    component: InscEdit,
    props: true
  }, {
    path: '/inscription/create',
    component: InscEdit
  }, {
    path: '/skill/list',
    component: SkillList
  }, {
    path: '/skill/edit/:id',
    component: SkillEdit,
    props: true
  }, {
    path: '/skill/create',
    component: SkillEdit
  }, {
    path: '/user/list',
    component: UserList
  }, {
    path: '/invi/list',
    component: InviList
  }, {
    path: '/invi/report',
    component: Report
  }, {
    path: '/chart/chart',
    component: Chart
  }, {
    path: '/information/list',
    component: InforList
  }, {
    path: '/information/edit/:id',
    component: InforEdit,
    props: true
  }, {
    path: '/information/create',
    component: InforEdit
  }]
}]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  const Token = window.sessionStorage.getItem('token')
  if (to.path === '/login') {
    return next()
  }
  if (!Token) {
    return next('/login')
  }
  next()
})
export default router
